home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / ici / ici.cpi / object.h < prev    next >
C/C++ Source or Header  |  1994-10-27  |  4KB  |  131 lines

  1. #ifndef    ICI_OBJECT_H
  2. #define    ICI_OBJECT_H
  3.  
  4. #ifndef    ICI_FWD_H
  5. #include "fwd.h"
  6. #endif
  7.  
  8. /*
  9.  * Every object has a header, the o_type field of which is a pointer
  10.  * to its type...
  11.  */
  12. struct type
  13. {
  14.     long    (*t_mark)();    /* Mark an object of this type. */
  15.     void    (*t_free)();    /* Free an object of this type. */
  16.     long    (*t_hash)();    /* Return a hash of the object's value. */
  17.     int        (*t_cmp)();    /* Object value compare (like types, eq => 0).*/
  18.     object_t    *(*t_copy)();    /* Copy of object of this type. */
  19.     int        (*t_assign)();    /* Assign to a sub element. */
  20.     object_t    *(*t_fetch)();    /* Fetch a sub element. */
  21.     char    *t_name;    /* As used by typeof() & errors. */
  22. };
  23.  
  24. #ifndef    SMALL
  25. /*
  26.  * Macros to perform the operation on the object.
  27.  */
  28. #define    mark(o)        ((objof(o)->o_flags & O_MARK) == 0 \
  29.                 ? (*(objof(o))->o_type->t_mark)(o) \
  30.                 : 0L)
  31. #define    freeo(o)    ((*(objof(o))->o_type->t_free)(o))
  32. #define    hash(o)        ((*(objof(o))->o_type->t_hash)(o))
  33. #define    cmp(o1,o2)    ((*(objof(o1))->o_type->t_cmp)((o1), (o2)))
  34. #define    copy(o)        ((*(objof(o))->o_type->t_copy)(o))
  35. #define    fetch(o,k)    ((*(objof(o))->o_type->t_fetch)((o), (k)))
  36. #define    assign(o,k,v)    ((*(objof(o))->o_type->t_assign)((o), (k), (v)))
  37. /*
  38.  * Link an object into the list of objects.
  39.  */
  40. #define    rego(o)        (objs_top < objs_limit \
  41.                 ? *objs_top++ = objof(o) \
  42.                 : grow_objs(objof(o)))
  43. #else
  44. /*
  45.  * Functions to performs operations on the object.
  46.  */
  47. extern long    mark();
  48. extern void    freeo();
  49. extern long    hash();
  50. extern int    cmp();
  51. extern object_t    *copy();
  52. extern object_t    *fetch();
  53. extern int    assign();
  54. extern void    rego();
  55. #endif
  56.  
  57. /*
  58.  * References from ordinary machine data objects (ie. variables and stuff,
  59.  * not other objects) are invisible to the garbage collector.  These refs
  60.  * must be accounted for if there is a possibility of garbage collection.
  61.  * Note that most routines that make objects (new_*(), copy() etc...)
  62.  * return objects with 1 ref.  The caller is expected to loose() it when
  63.  * they attach it into wherever it is going.
  64.  */
  65. #ifndef    BUGHUNT
  66. #define    got(o)        (++objof(o)->o_nrefs)
  67. #define    loose(o)    (--objof(o)->o_nrefs)
  68. #endif
  69.  
  70. /*
  71.  * This is the universal header of all objects.
  72.  */
  73. struct object
  74. {
  75.     char    o_tcode;    /* See TC_* below. */
  76.     char    o_flags;    /* See O_* below. */
  77.     char    o_nrefs;    /* No. of refs invisible to collect. */
  78.     char    o_pad;        /* Waiting for a use. */
  79.     type_t    *o_type;    /* See struct type above. */
  80.     /*
  81.      * Each object includes this as a header.  In the real structures
  82.      * associated with each object type the type specific stuff follows...
  83.      */
  84. };
  85. #define    objof(x)    ((object_t *)(x))
  86. /*
  87.  * For static object initialisations...
  88.  */
  89. #define    OBJ(tc,type)    {(tc), 0, 1, 0, &type}
  90.  
  91. /*
  92.  * The upper nibble is considered available for type specific use.
  93.  */
  94. #define    O_MARK        0x01    /* Garbage collection mark. */
  95. #define    O_ATOM        0x02    /* Is a member of the atom pool. */
  96.  
  97. /*
  98.  * The o_tcode field is a small int which allows bypassing the o_type
  99.  * pointer for some types.  Any type not listed here will have a value
  100.  * of 0.  The types listed will set a code here to allow some time
  101.  * critical areas of code to make quicker decisions (typically a switch)
  102.  * based on the type.  It also allows faster decisions based on type
  103.  * combinations (see pair() below).
  104.  */
  105. #define    TC_OTHER    0
  106. #define    TC_PC        1
  107. #define    TC_SRC        2
  108. #define    TC_PARSE    3
  109. #define    TC_OP        4
  110. #define    TC_STRING    5
  111. #define    TC_CATCH    6
  112. #define    TC_FORALL    7
  113. #define    TC_INT        8
  114. #define    TC_FLOAT    9
  115. #define    TC_REGEXP    10
  116. #define    TC_PTR        11
  117. #define    TC_ARRAY    12
  118. #define    TC_STRUCT    13
  119. #define    TC_SET        14
  120. /* Max value of 15 dictated by PAIR (below). */
  121.  
  122. #define    PAIR(a,b)    (((a) << 4) + (b))
  123. #define    TRI(a,b,t)    (((((a) << 4) + b) << 6) + t_subtype(t))
  124.  
  125. #ifndef    ICI_NULL_H
  126. #include "null.h"
  127. #endif
  128.  
  129. #define    isfalse(o)    ((o) == objof(o_zero) || isnull(o))
  130. #endif
  131.